import {CLOSE_LIVE_VIDEO, OPEN_LIVE_VIDEO, QUERY,} from '../types/LiveType'
import {queryService} from "../service/Live";

const queryAction = () => {
  return (dispatch) => {
    queryService().then(res => {
      dispatch(query(res.data));
    }).catch(err => {
      dispatch(
        {
          type: "ERROR",
          payload: {
            err: err
          }
        }
      )
    })
  }
}

const query = (data) => {
  return {
    type: QUERY,
    payload: data.data.map(it => {
      it.key = it.id;
      return it
    }),
  }
}

const openLiveVideo = (record) => {
  return {
    type: OPEN_LIVE_VIDEO,
    liveVideoVisible: true,
    videoRecord: record
  }
}
const liveVideoClose = () => {
  return {
    type: CLOSE_LIVE_VIDEO,
    liveVideoVisible: false,
  }
}

export {
  queryAction,
  openLiveVideo,
  liveVideoClose
}